Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REG-1463] Generate 'partial' class to attach RGState and RGAction to host behavior #116

Merged
merged 5 commits into from
Dec 11, 2023

Conversation

analogrelay
Copy link
Contributor

This updates our Unity code gen to add partial classes that create a RequireComponent dependency from the "host" behavior (the MonoBehavior on which the [RGState] or [RGAction] attribute is placed) to the generated RGState_[HostBehaviorName] and RGAction_[HostBehaviorName] components. This signals to the Unity editor, when reimporting assets, to add the RGState_.../RGAction_... components to any GameObject that also has the host behavior attached. This mostly allows us to "auto-attach" the behaviors.

From my testing, this is fairly consistent. Unity does caution that it doesn't check dependencies in all scenarios, but it does it whenever GameObject.AddComponent is called.

In order to generate this auto-attach class, we need the original host behavior to be marked as a partial class. I added code to check for that and report an error if that's not the case. WIth the changes in #105, this also causes a dialog to pop up to draw your attention to the log:

image

NOTE: One additional change I made is to restore the "Generate Scripts" menu item. After #105 merged, auto-generation is mostly working but there are a few scenarios where I've noticed it doesn't work:

  1. If you change anything in the RegressionGames packages, it doesn't re-generate. This mostly affects us
  2. If you delete or otherwise mess with the generated code (perhaps accidentally).

Both cases are fairly rare (case 1 is mostly just for us), but it seems reasonable to me to bring back the ability to manually regenerate the scripts, even if it's only needed in edge cases.


Find the pull request instructions here

Every reviewer and the owner of the PR should consider these points in their request (feel free to copy this checklist so you can fill it out yourself in the overall PR comment)

  • The code is extensible and backward compatible
  • New public interfaces are extensible and open to backward compatibility in the future
  • If preparing to remove a field in the future (i.e. this PR removes an argument), the argument stays but is no longer functional, and attaches a deprecation warning. A linear task is also created to track this deletion task.
  • Non-critical or potentially modifiable arguments are optional
  • Breaking changes and the approach to handling them have been verified with the team (in the Linear task, design doc, or PR itself)
  • The code is easy to read
  • Unit tests are added for expected and edge cases
  • Integration tests are added for expected and edge cases
  • Functions and classes are documented
  • Migrations for both up and down operations are completed
  • A documentation PR is created and being reviewed for anything in this PR that requires knowledge to use
  • Implications on other dependent code (i.e. sample games and sample bots) is considered, mentioned, and properly handled
  • Style changes and other non-blocking changes are marked as non-blocking from reviewers

@analogrelay
Copy link
Contributor Author

Resolved a gnarly enough conflict that I'd like to get re-reviews (particularly from @RG-nAmKcAz since that's where the conflict arose and I want to make sure I didn't blast away his changes). I'll do another smoke-test to make sure things are working.

And I see you already approved 🤣 . Thanks @RG-nAmKcAz !

@nAmKcAz
Copy link
Collaborator

nAmKcAz commented Dec 11, 2023

Resolved a gnarly enough conflict that I'd like to get re-reviews (particularly from @RG-nAmKcAz since that's where the conflict arose and I want to make sure I didn't blast away his changes). I'll do another smoke-test to make sure things are working.

And I see you already approved 🤣 . Thanks @RG-nAmKcAz !

For clarity, I'm not hand inspecting the code to see if you merged it correctly. I would expect the dev themselves to do that as necessary. I didn't see anything obvious though at a high level glance.

@analogrelay
Copy link
Contributor Author

For clarity, I'm not hand inspecting the code to see if you merged it correctly. I would expect the dev themselves to do that as necessary. I didn't see anything obvious though at a high level glance.

Yep, that's my expectation too, but I think it's always valuable for the conflicting commit author to take a scan over it. Thanks for looking!

@analogrelay
Copy link
Contributor Author

There was one small style change lost in the conflict resolution. I've restored that: 16e8995

@analogrelay analogrelay merged commit 1a48f2f into main Dec 11, 2023
2 checks passed
@analogrelay analogrelay deleted the ashley/reg-1463 branch December 11, 2023 22:54
@analogrelay analogrelay restored the ashley/reg-1463 branch December 13, 2023 17:52
analogrelay added a commit that referenced this pull request Dec 13, 2023
addisonbgross pushed a commit that referenced this pull request Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants